package com.example.service.impl;

import cn.hutool.crypto.SecureUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.common.ResultCode;
import com.example.dao.*;
import com.example.entity.Dianyingfenlei;
import com.example.exception.CustomException;
import com.example.service.DianyingfenleiService;
import com.example.vo.DianyingfenleiVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
import java.util.Map;

@Service("dianyingfenleiService")
public class DianyingfenleiServiceImpl extends ServiceImpl<DianyingfenleiDao, Dianyingfenlei> implements DianyingfenleiService {

    @Resource
    private DianyingfenleiDao dianyingfenleiDao;

    public Dianyingfenlei add(Dianyingfenlei dianyingfenlei) {
		
	   //youquchong1
        dianyingfenlei.setAddtime(new Date());
        dianyingfenleiDao.insert(dianyingfenlei);
        return dianyingfenlei;
    }
	
	
	
    public void delete(Long id) {
        dianyingfenleiDao.deleteById(id);
    }
	

    public void update(Dianyingfenlei dianyingfenlei) {
        //youquchong2
        dianyingfenleiDao.updateById(dianyingfenlei);
    }
	
	@Override
    public List<Map<String, Object>> daochuexcel() {
        return dianyingfenleiDao.daochuexcel();
    }

    @Override
    public Dianyingfenlei findById(Integer id) {
        return dianyingfenleiDao.selectById(id);
    }

    public DianyingfenleiVo findPage(DianyingfenleiVo dianyingfenleiVo) {
        LambdaQueryWrapper<Dianyingfenlei> wrapper = Wrappers.lambdaQuery();
		wrapper.like(ObjectUtils.isNotEmpty(dianyingfenleiVo.getPlr()), Dianyingfenlei::getPlr,dianyingfenleiVo.getPlr());
		wrapper.like(ObjectUtils.isNotEmpty(dianyingfenleiVo.getDyId()), Dianyingfenlei::getDyId,dianyingfenleiVo.getDyId());

        Page<Dianyingfenlei> page = new Page<>(dianyingfenleiVo.getCurrent(),dianyingfenleiVo.getCurrentNum());
        dianyingfenleiDao.selectPage(page,wrapper);
        List<Dianyingfenlei> dianyingfenleis = page.getRecords();
        dianyingfenleiVo.setList(dianyingfenleis);
        dianyingfenleiVo.setPages(page.getPages());
        dianyingfenleiVo.setTotal(page.getTotal());
        dianyingfenleiVo.setCurrent(page.getCurrent());
        dianyingfenleiVo.setCurrentNum(page.getSize());
        return dianyingfenleiVo;
    }

    @Override
    public void deleteList(List<Dianyingfenlei> list) {
        List<Integer> ids =  list.stream().map(Dianyingfenlei::getId).collect(Collectors.toList());
        dianyingfenleiDao.deleteBatchIds(ids);
    }
	
	
	
	
	
	//youxxianxci
}
